
import { HierarchicalStateMachine } from "./HierarchicalStateMachine";
import {  HSMBase } from "./HSMBase";
import { ITransition } from "./Transition";


export   class State<T extends IStateArg = IStateArg> extends HSMBase<T>
{
  
    private parent!:HierarchicalStateMachine ;
    private transitions:ITransition<T>[] = [];
    public name:string;
    public index!:number;
    constructor(HSM?:HierarchicalStateMachine)
    {
        super();
        if(HSM)
        {
            this.setParent(HSM);
        }
        this.name = this.constructor.name;
    }
    public setParent(HSM:HierarchicalStateMachine)
    {
        this.parent = HSM;
    }



    public  get Parent():HierarchicalStateMachine
    {
        return this.parent;
    }
    public addTransition(transition:ITransition<T>)
    {
        transition.setOrigin(this);
        this.transitions.push(transition);
    }

    public getStates(): State[]
    {
        return [this];
    }
    public getStateIndex():number[]
    {
        return []
    }
    //
    public  getActions(arg:T):Action[]
    {
        return [ ];
    }

    public getEntryActions(arg:T):Action[]
    {
        return [ ];
    }

    public getExitActions(arg:T):Action[]
    {
        return [ ];
    }

    public getTransitions():ITransition<T>[]
    {
        return this.transitions;
    }

    public getLevel(): number
    {
        return this.parent.getLevel()+1;
    }


    protected DebugTask(task:any,mask:number=0,key:string="")
    {
        if(mask)
        {
            if(mask == 1 && task.code == key)
            {
                global.Log.Warning(`[Debug] ${this.constructor.name}   ${JSON.stringify(task)}`);
            }
            else if (mask == 2 && task.ID == key)
            {
                global.Log.Warning(`[Debug] ${this.constructor.name}   ${JSON.stringify(task)}`);
            }
        }
        else
        {
            global.Log.Warning(`[Debug] ${this.constructor.name}   ${JSON.stringify(task)}`);
        }

    }
}
